package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 统计报表业务逻辑层实现类
 */
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    /**
     * 统计员工职位数据
     *
     * @return
     */
    @Override
    public JobOption empJobData() {
        //[{学工主管，18}，{教研部，20}，。。。。]
        //1.查询职位数据
        List<Map<String, Object>> list = empMapper.empJobData();
        //2.封装数据
        List<Object> jobList = list.stream().map(item ->
                item.get("pos")
        ).toList();
        List<Object> dataList = list.stream().map(item ->
                item.get("total")
        ).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> empGenderData() {
        return empMapper.empGenderData();
    }
}
